package com.netty.server.threadpool;

import java.util.concurrent.ThreadPoolExecutor;

/**
 * @author 作者 : 陈怀傲
 * @version 创建时间：2015年4月18日 下午3:12:19 类说明
 */
public class TestMain implements Runnable {
	private int taskNum;

	private TestMain(int taskNum) {
		this.taskNum = taskNum;
	}

	public static void main(String[] args) {
		System.out.println("10000000000000l:" + Integer.MAX_VALUE);
		// for (int w = 0; w < 11; w++) {
		ThreadPoolExecutor executor = ExecutorPool.getSingleton().getExecutor();
		int size = 0;
		for (int i = 0; i < 10; i++) {
			for (int j = 0; j < 10; j++) {
				size++;
				TestMain myTask = new TestMain(size);
				executor.execute(myTask);
				System.out.println("线程池中线程数目：" + executor.getPoolSize()
						+ "，队列中等待执行的任务数目：" + executor.getQueue().size()
						+ "，已执行玩别的任务数目：" + executor.getCompletedTaskCount());
			}
		}
		System.out.println("================" + executor.getQueue().size());
		System.out.println(executor);
		// }

	}

	@Override
	public void run() {
		System.out.println("正在执行task " + taskNum);
		try {
			Thread.currentThread().sleep(4000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		System.out.println("task " + taskNum + "执行完毕");
	}
}
